package com.SouthernWall_404.Age_Capitalism.common.API.Info;

import com.SouthernWall_404.Age_Capitalism.AgeCapitalism;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import org.checkerframework.checker.units.qual.C;

import java.util.UUID;

public class StoreKeyInfo {

    public BlockPos blockPos;
    public String block_name;
    public UUID uuid;

    public StoreKeyInfo(BlockPos blockPos, String block, UUID uuid) {
        this.blockPos = blockPos;
        this.block_name = block;
        this.uuid = uuid;
    }

    public StoreKeyInfo(int x,int y,int z,String block,UUID uuid)
    {
        this(new BlockPos(x,y,z),block,uuid);
    }

    public StoreKeyInfo()
    {
        this.blockPos =new BlockPos(0,0,0);
        this.block_name =" ";
        this.uuid = UUID.randomUUID();
    }

    public static StoreKeyInfo getFromItem(ItemStack itemStack)
    {
        CompoundTag nbt=itemStack.getOrCreateTag();
        StoreKeyInfo storeKeyInfo=new StoreKeyInfo();
        if(!nbt.isEmpty())
        {
            CompoundTag modPack=(CompoundTag) nbt.get(AgeCapitalism.MODID);
            storeKeyInfo=getFromModPack(modPack);
        }
        return storeKeyInfo;
    }

    public static StoreKeyInfo getFromModPack(CompoundTag modPack)
    {
        StoreKeyInfo storeKeyInfo=new StoreKeyInfo();
        if(modPack.contains("keyPack"))
        {
            CompoundTag keyPack=(CompoundTag) modPack.get("keyPack");
            storeKeyInfo=getFromKeyPack(keyPack);
        }

        return storeKeyInfo;
    }
    public static StoreKeyInfo getFromKeyPack(CompoundTag keyPack)
    {
        StoreKeyInfo storeKeyInfo=new StoreKeyInfo();
        if(!keyPack.isEmpty())
        {
            int x=keyPack.getInt("x");
            int y=keyPack.getInt("y");
            int z=keyPack.getInt("z");
            String block=keyPack.getString("block");
            String uuid_string=keyPack.getString("uuid");
            UUID uuid=UUID.fromString(uuid_string);

            storeKeyInfo=new StoreKeyInfo(x,y,z,block,uuid);
        }

        return storeKeyInfo;
    }
}
